import 'package:xiaomi_shop/app/services/storage.dart';
import 'package:xiaomi_shop/models/index.dart';

class UserService {
  static saveUser(Map userInfo) async {
    var result = await Storage.setData("userInfo", userInfo);
    print("result $result");
  }

  // 获取用户信息
  static Future<UserModel?> getUser() async {
    var userInfo = await Storage.getData("userInfo");
    if (userInfo != null) {
      return UserModel.fromJson(userInfo);
    }
    return null;
  }

  // 获取登录状态
  static Future<bool> getUserLoginState() async {
    UserModel? user = await getUser();
    if (user != null && user.username!.isNotEmpty) {
      return true;
    } else {
      return false;
    }
  }

  // 退出登录
  static void loginOut() async {
    await Storage.removeData("userInfo");
  }
}
